﻿
using Com.Mapabc.Maps.Api.BaseTypes;
using System;
using Com.Mapabc.Maps.Api.Overlays;
namespace LantinxLBS.Common
{
    public class MapHelper
    {
        public static double GetBuffer(int level)
        {
            double buffer = 1;

            switch (level)
            {
                case 1:
                    buffer = 20;
                    break;
                case 2:
                case 3:
                    buffer = 10;
                    break;
                case 4:
                case 5:
                    buffer = 5;
                    break;

                case 6:
                case 7:
                    buffer = 1;
                    break;
                case 8:
                case 9:
                    buffer = 0.1;
                    break;
                case 10:
                case 11:
                    buffer = 0.08;
                    break;

                case 12:
                    buffer = 0.005;
                    break;
                case 13:
                    buffer = 0.002;
                    break;
                case 14:
                case 15:
                    buffer = 0.001;
                    break;
                case 16:
                case 17:
                    buffer = 0.0005;
                    break;
            }
            return buffer;
        }

        public static int GetZoom(MLngLat lng, MLngLat lat)
        {
            double x = Math.Abs(lng.X - lat.X);
            double y = Math.Abs(lng.Y - lat.Y);
            int zoom = 1;
            double k = Math.Max(x, y);
            zoom = (k < 100) ? zoom = 2 : zoom;
            zoom = (k < 50) ? zoom = 3 : zoom;
            zoom = (k < 20) ? zoom = 4 : zoom;
            zoom = (k < 10) ? zoom = 5 : zoom;
            zoom = (k < 5) ? zoom = 6 : zoom;
            zoom = (k < 3) ? zoom = 7 : zoom;
            zoom = (k < 2.95) ? zoom = 8 : zoom;
            zoom = (k < 2.9) ? zoom = 9 : zoom;
            zoom = (k < 1.7) ? zoom = 10 : zoom;
            zoom = (k < 1.5) ? zoom = 11 : zoom;
            zoom = (k < 1.2) ? zoom = 12 : zoom;
            zoom = (k < 1) ? zoom = 13 : zoom;
            zoom = (k < 0.2) ? zoom = 14 : zoom;
            zoom = (k < 0.15) ? zoom = 15 : zoom;
            zoom = (k < 0.1) ? zoom = 16 : zoom;
            zoom = (k < 0.01) ? zoom = 17 : zoom;
            return zoom;
        }

        public static MLngLat GetCenter(MLngLat lng, MLngLat lat)
        {
            return new MLngLat((lng.X + lat.X) / 2.0D, (lng.Y + lat.Y) / 2.0D);
        }

        public static MTip GetMTip(string markName,string address,string description)
        {
            MTip tip = new MTip();
            tip.Title = markName;
            tip.Content = "地址:" + address + "\n" + "描述:" + description;
            return tip;
        }
    }
}
